package com.campus.utils;

import java.io.IOException;
import java.net.MalformedURLException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class WebViewUtils {

	public static final String HTTPHOST = "http://news.xaufe.edu.cn/";

	public static String handle(String resp) throws MalformedURLException,
			IOException {
		Document s = Jsoup.parse((resp));
		Elements e = s.select("div#web2l");
		Elements pngs = e.select("img[src]");
		for (Element element : pngs) {
			String imgUrl = element.attr("src");
			if (imgUrl.trim().startsWith("/")) {
				imgUrl = HTTPHOST + imgUrl;
				element.attr("src", imgUrl);
			}
		}
		return e.toString();

	}

	public static String okresp(String resp) throws MalformedURLException,
			IOException {
		Document doc = Jsoup.parse(resp);
		String s = "div#xaufe_middiv";
		return handle((doc.select(s).toString()));
	}

	public static String okresp(String resp, String select)
			throws MalformedURLException, IOException {
		Document doc = Jsoup.parse(resp);
		String s = select;
		return handle((doc.select(s).toString()));
	}
}
